package controller.role;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.RoleService;
import service.impl.RoleServiceImpl;
import utils.AJAXResult;
import utils.ResponseBodyUtil;

public class DoAssign extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private RoleService roleService = new RoleServiceImpl();
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		AJAXResult result = new AJAXResult();
		String roleid = request.getParameter("roleid");
		String[] permissionids = request.getParameterValues("permissionids");
		try {
			
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("roleid", roleid);
			paramMap.put("permissionids", permissionids);
			roleService.insertRolePermission(paramMap);
			
			result.setSuccess(true);
		} catch ( Exception e ) {
			e.printStackTrace();
			result.setSuccess(false);
		}
		
		ResponseBodyUtil.sendJsonObject(response, result);
	}

}
